package com.chzu;

import com.chzu.mapper.DataSourceMapper;
import com.chzu.pojo.DataSource;
import com.chzu.service.IDataSourceService;
import com.chzu.utils.GlobalCache;
import com.chzu.utils.JdbcUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author liangzhuo
 * @create 2021-10-22-20:32
 */
@Component
public class ApplicationRunnerImpl implements ApplicationRunner {

    @Resource
    private IDataSourceService dataSourceService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        DataSource dataSourceSelectByState = new DataSource();
        dataSourceSelectByState.setIsActive(0);
        //查询数据源配置
        List<String> dataSourceList = JdbcUtils.initCache(dataSourceService.list());
        /*全局注入各表的数据源信息*/
        GlobalCache.pojoList = dataSourceService.list();
        /*全局注入汇总库的全部表名，除去记录表和数据源表*/
        GlobalCache.AllTables = dataSourceService.getAlltables();
    }
}

